home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.netins.net!isac!gg
- From: gg@isac.hces.com (Greg Goodrich)
- Subject: Re: about free()
- Message-ID: <1996Feb28.195932.10666@isac.hces.com>
- Organization: Health Care Expert Systems
- X-Newsreader: TIN [version 1.2 PL2]
- References: <31333454.167E@mashie.ece.jhu.edu>
- Date: Wed, 28 Feb 1996 19:59:32 GMT
-
- chenyang@mashie.ece.jhu.edu wrote:
- : Hi, there,
-
- : I have a simple question here.
-
- : I have a function say newarrary() which mallocs an array inside and
- : returns a pointer to this arrary. In another function foo.c, the result
- : of newarray() is assigned to a pointer ptr. Now after some operations on
- : this array. I use free(ptr) to free the memory allocated by newarrary().
- : My question is whould this cause a problem, since free() is not freeing
- : the same pointer which is allocated by the malloc() although this
- : pointer point to the same memory.
-
- The only thing that is important for freeing a dynamically allocated
- variable is the address of the allocated space. The ptr merely contains
- this address, and it does not matter what variable you use to free the
- space as long as you are passing the same address to the free call that
- the malloc call returned.
-
- Greg.
- --
- _______________________________________
- Greg Goodrich - gg@hces.com
- Software Engineer
- PACE Health Management Systems
-